package com.andy.beef.ui.main.adapter

import android.widget.ImageView
import com.andy.beef.R
import com.andy.beef.ui.main.bean.ServicePointBean
import com.blankj.utilcode.util.NumberUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @creator:LuoFan
 * @date:2022/6/6
 * @description:
 */
class ServicePointAdapter : BaseQuickAdapter<ServicePointBean, BaseViewHolder>(R.layout.main_adapter_choose_service_point) {

    private var selectPosition = -1

    override fun convert(holder: BaseViewHolder, item: ServicePointBean) {
        holder.setText(R.id.tv_name, item.pointName)
        holder.setText(R.id.tv_address, item.address)
        val distance = NumberUtils.format(item.distanceCurrent / 1000, 2) + "km"
        holder.setText(R.id.tv_distance, distance)
        holder.getView<ImageView>(R.id.img_select).isSelected = holder.adapterPosition == selectPosition
    }

    fun setSelectPosition(position: Int) {
        selectPosition = position
        notifyDataSetChanged()
    }

    fun getSelectPosition(): Int {
        return selectPosition
    }
}